package com.ww.aiinterviewer.model.vo;

import cn.hutool.json.JSONUtil;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.ww.aiinterviewer.model.entity.ChatRoom;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author 15357
 * @create 2025/5/13 16:26
 */
@Data
public class ChatRoomVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 内容
     */
    private List<ChatMessage> messageList;

    /**
     * 创建人信息
     */
    private UserVO user;

    /**
     * 包装类转对象
     * @param chatRoomVO
     * @author wangwang
     * @date 2025/5/13
     */
    public static ChatRoom voToObj(ChatRoomVO chatRoomVO) {
        if (chatRoomVO == null) {
            return null;
        }
        ChatRoom chatRoom = new ChatRoom();
        BeanUtils.copyProperties(chatRoomVO, chatRoom);
        List<ChatMessage> messageList = chatRoomVO.getMessageList();
        chatRoom.setMessages(JSONUtil.toJsonStr(messageList));
        return chatRoom;
    }

    /**
     * 对象转包装类
     * @param chatRoom
     * @author wangwang
     * @date 2025/5/13
     */
    public static ChatRoomVO objToVo(ChatRoom chatRoom) {
        if (chatRoom == null) {
            return null;
        }
        ChatRoomVO chatRoomVO = new ChatRoomVO();
        BeanUtils.copyProperties(chatRoom, chatRoomVO);
        String messages = chatRoom.getMessages();
        List<ChatMessage> contentList = JSONUtil.toList(messages, ChatMessage.class);
        chatRoomVO.setMessageList(contentList);
        return chatRoomVO;
    }

    private static final long serialVersionUID = 1L;

}
